<?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use App\Models\Access\Permission\Permission;
class PermissionsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //执行节点
        $node = [
           'user-p' => '用户管理',//-p父节点
           'user-add' => '添加',
           'user-index' => '查看',
           'user-update' => '修改',
           'user-delete' => '禁用',
           'user-restore' => '启用',
           'role-p' => '角色管理',
           'role-add' => '添加',
           'role-index' => '查看',
           'role-update' => '修改',
           'role-delete' => '删除',
           'permission-p' => '节点管理',
           'permission-add' => '添加',
           'permission-index' => '查看',
           'permission-update' => '修改',
           'ogz-p' => '组织机构管理',
           'ogz-add' => '添加',
           'ogz-index' => '查看',
           'ogz-update' => '修改',
           'ogz-delete' => '禁用',
           'ogz-restore' => '启用',
           'qyapp-p' => '企业应用管理',
           'qyapp-add' => '添加',
           'qyapp-index' => '查看',
           'qyapp-update' => '修改',
           'qyapp-delete' => '禁用',
           'qyapp-restore' => '启用',
           'qyapp-export' => '导出',
           'flow-p' => '漏洞管理',
           'vuls-add' => '添加',
           'vuls-index' => '查看',
           'vuls-update' => '编辑',
           'vuls-delete' => '禁用',
           'vuls-detail' => '查看详情',
           'vuls-audit' => '初审',
           'vuls-confirm' => '状态流确认',
           'vuls-checkForm' =>'待审核',//new start
            'vuls-noEffect'=>'无影响',
            'vuls-ignoreForm'=>'已忽略',
           'vuls-checkedForm' =>'已审核',
           'vuls-ensureForm' =>'待确认',
            'vuls-appealForm' =>'申诉中',
            'vuls-appealFormView'=>'申诉查看',
           'vuls-repairForm' =>'待修复',
           'vuls-confirmForm' =>'已修复',
            'vuls-confirmView' =>'已修复查看',
            'vuls-solvedForm'=>'已解决',
           'vuls-shutDownForm' =>'关闭',
           'vuls-sentencepoints'=>'重判积分等级',
           'vuls-vulsreedit'=>'重新编辑等级积分',//new end
           'vuls-restore' =>'启用',
           'vuls-forcedel' =>'强制删除',
           'vuls-distribute-d' =>'分发',//-d删除
           'vuls-delay' => '延期',
           'vuls-auditdelay' => '审核延期',
           'addition-export' => '导出',
           'cate-p' => '漏洞菜单管理',
           'cate-add' => '添加',
           'cate-index' => '查看',
           'cate-update' => '编辑',
           'cate-delete' => '禁用',
           'cate-restore' =>'恢复',
           'cate-forcedel' =>'彻底删除',
           'level-p' => '等级评分管理',
           'level-add' => '添加',
           'level-index' => '查看',
           'level-update' => '编辑',
           'level-delete' => '禁用',
           'level-restore' =>'恢复',
           'level-forcedel' =>'彻底删除',
           'log-p' => '日志管理',
           'log-index' => '查看',
           'chartsanalysis-p' =>'图表分析',
           'chartsanalysis-index' =>'集团信息',
           'chartsanalysis-subblock' => '板块信息',
           'chartsanalysis-company' => '公司信息',
           'chartsanalysis-export' => '导出',
            /*商品及分类权限*/
            'goods-p' => '商品管理',
            'goods-add' => '添加',
            'goods-index' => '查看',
            'goods-update' => '编辑',
            'goods-delete' => '删除',
            'goods-restore' =>'恢复',
            'goods-forcedel' =>'彻底删除',
            'goodscate-p' => '商品分类管理',
            'goodscate-add' => '添加',
            'goodscate-index' => '查看',
            'goodscate-update' => '编辑',
            'goodscate-delete' => '删除',
            'goodscate-restore' =>'恢复',
            'goodscate-forcedel' =>'彻底删除',
            /*兑换记录权限*/
            'order-p' => '兑换记录管理',
            'order-index' => '查看',
            'order-update' => '编辑',
            'order-delete' => '删除',
            'order-restore' =>'恢复',
            'order-forcedel' =>'彻底删除',
            /*公告管理*/
            'announce-p' => '公告管理',
            'announce-index' => '列表',
            'announce-det' => '详情',
            'announce-modify' => '编辑',
            'announce-move' => '删除',
            'announce-publish' => '发布',
            'announce-new' =>'新增',
            /*漏洞分发*/
            'disrtibute-p' => '我的漏洞',
            'distribute-distribute' => '漏洞分发',
           /*项目管理*/
           'projectmanage-p'=>'项目管理',
           'projectmanage-index'=>'查看',
           'projectmanage-add'=>'添加',
           'projectmanage-update'=>'修改',
           'projectmanage-detail'=>'详情',
           'projectmanage-export'=>'导出',
           /*检查项*/
           'checkoption-p'=>'检查项',
           'checkoption-index'=>'查看',
           'checkoption-add'=>'添加',
           'checkoption-projectvuls'=>'查看漏洞',
           /*系统管理*/
           'sysconfig-p'=>'系统配置',
           'sysconfig-index'=>'查看',
           'sysconfig-set'=>'设置',
           'sysconfig-send'=>'发送邮件',
           /*安全知识库*/
           'knowledge-p'=>'安全知识库',
           'knowledge-add'=>'添加',
           'knowledge-update'=>'修改',
           'knowledge-settop'=>'置顶',
           'knowledge-detail'=>'详情'
        ];
        foreach ($node as $item =>  $value){
            $itemArr = explode('-',$item);
            if (isset($itemArr[2]) && $itemArr[2] == 'd') {
                Permission::where(['code'=>$itemArr[0].'-'.$itemArr[1]])->delete();
                continue;
            }
            if ($itemArr[1] == 'p'){
                $pData['name'] = $value;
                $pData['action_type'] = 1;
                $pData['sort'] = 0;
                $pData['created_at'] = Carbon::now();
                $permission = Permission::updateOrCreate(['code'=>$itemArr[0]],$pData);
            }else{
                $data['name'] = $value;
                $data['action_type'] = 1;
                $data['sort'] = 0;
                $data['pid'] = isset($permission) ? $permission->id : 0;
                $data['created_at'] = Carbon::now();
                Permission::updateOrCreate(['code'=>$item],$data);
            }
        }
    }
}
